import { isEmptyArray } from './index';

const TOKEN = 'ACCESS_TOKEN';
// token
export function setToken(token: string) {
  localStorage.setItem(TOKEN, token);
}
export function getToken() {
  return localStorage.getItem(TOKEN);
}
export function removeToken() {
  localStorage.removeItem(TOKEN);
}

// 单位id
export function setDeptCascaderId(deptIdList: (string | number | null)[]) {
  if (!isEmptyArray(deptIdList)) {
    localStorage.setItem('DEPT_ID_LIST', JSON.stringify(deptIdList));
  }
}
export function getDeptCascaderId(): Array<string> {
  return localStorage.getItem('DEPT_ID_LIST')
    ? JSON.parse(localStorage.getItem('DEPT_ID_LIST') as string)
    : [];
}
export function removeDeptId() {
  localStorage.removeItem('DEPT_ID_LIST');
}

// 账套id
export function setAccountSetId(id: string) {
  localStorage.setItem('ACCOUNT_SET_ID', id);
}
export function getAccountSetId() {
  return localStorage.getItem('ACCOUNT_SET_ID');
}
export function removeAccountSetId() {
  localStorage.removeItem('ACCOUNT_SET_ID');
}

export function storageLogout() {
  removeToken();
  removeDeptId();
  removeAccountSetId();
}
